<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 29] 29.9 java.text.DecimalFormat (JDK 1.1)</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:33:06 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch29_08.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 29<br>The java.text Package</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch29_10.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-9">29.9 java.text.DecimalFormat (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-9.1"></A></h3>
</DIV>

<P CLASS=para>
This is the concrete <tt CLASS=literal>Format</tt> class used by
<tt CLASS=literal>NumberFormat</tt> for all locales that use base 10
numbers.  Most applications do not need to use this class
directly--they can use the static methods of
<tt CLASS=literal>NumberFormat</tt> to obtain a default <tt CLASS=literal>NumberFormat</tt> object
for a desired locale, and may then perform minor
locale-independent customizations on that object.

<P CLASS=para>
Applications that require highly-customized number
formatting and parsing may create custom
<tt CLASS=literal>DecimalFormat</tt> objects by passing a suitable pattern
to the <tt CLASS=literal>DecimalFormat()</tt> constructor method.  The
<tt CLASS=literal>applyPattern()</tt> method can be used to change this
pattern.  A pattern consists of a string of characters from
the following table.  For example: "$#,##0.00;($#,##0.00)".

<DIV CLASS=informaltable>
<P>
<A NAME="JNUT2-CH-29-TAB-1"></A>

<TABLE CLASS=INFORMALTABLE>
<TR CLASS=row>
<TH ALIGN="left">Character</TH>
<TH ALIGN="left">Meaning</TH>
</TR>
<TR CLASS=row>
<TD ALIGN="left">#</TD>
<TD ALIGN="left">A digit; zeros show as absent</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">0</TD>
<TD ALIGN="left">A digit; zeros show as 0</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">.</TD>
<TD ALIGN="left">The locale-specific decimal separator</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">,</TD>
<TD ALIGN="left">The locale-specific grouping separator</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">-</TD>
<TD ALIGN="left">The locale-specific negative prefix</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">%</TD>
<TD ALIGN="left">Show value as a percentage</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">;</TD>
<TD ALIGN="left">

<P CLASS=para>
Separates positive number format (on left) from optional
negative number format (on right)</TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left">'</TD>
<TD ALIGN="left">

<P CLASS=para>
Quote a reserved character, so it appears literally in the output </TD>
</TR>
<TR CLASS=row>
<TD ALIGN="left"><I CLASS=emphasis>other</I></TD>
<TD ALIGN="left">Appears literally in output</TD>
</TR>
</TABLE>
<P>
</DIV>

<P CLASS=para>
A <tt CLASS=literal>DecimalFormatSymbols</tt> object may be optionally
specified when creating a <tt CLASS=literal>DecimalFormat</tt> object.  If
one is not specified, a <tt CLASS=literal>DecimalFormatSymbols</tt> object
suitable for the default locale is used.

<DIV CLASS=screen>
<P>
<PRE>
public class <tt CLASS=literal>DecimalFormat</tt> extends NumberFormat {
    // <tt CLASS=literal>Public Constructors</tt>
            public <tt CLASS=literal>DecimalFormat</tt>();
            public <tt CLASS=literal>DecimalFormat</tt>(String <tt CLASS=literal>pattern</tt>);
            public <tt CLASS=literal>DecimalFormat</tt>(String <tt CLASS=literal>pattern</tt>, DecimalFormatSymbols <tt CLASS=literal>symbols</tt>);
    // <tt CLASS=literal>Public Instance Methods</tt>
            public void <tt CLASS=literal>applyLocalizedPattern</tt>(String <tt CLASS=literal>pattern</tt>);
            public void <tt CLASS=literal>applyPattern</tt>(String <tt CLASS=literal>pattern</tt>);
            public Object <tt CLASS=literal>clone</tt>();  //<tt CLASS=literal> Overrides NumberFormat</tt>
            public boolean <tt CLASS=literal>equals</tt>(Object <tt CLASS=literal>obj</tt>);  //<tt CLASS=literal> Overrides NumberFormat</tt>
            public StringBuffer <tt CLASS=literal>format</tt>(double <tt CLASS=literal>number</tt>, StringBuffer <tt CLASS=literal>result</tt>, FieldPosition <tt CLASS=literal>fieldPosition</tt>);  //<tt CLASS=literal> Defines NumberFormat</tt>
            public StringBuffer <tt CLASS=literal>format</tt>(long <tt CLASS=literal>number</tt>, StringBuffer <tt CLASS=literal>result</tt>, FieldPosition <tt CLASS=literal>fieldPosition</tt>);  //<tt CLASS=literal> Defines NumberFormat</tt>
            public DecimalFormatSymbols <tt CLASS=literal>getDecimalFormatSymbols</tt>();
            public int <tt CLASS=literal>getGroupingSize</tt>();
            public int <tt CLASS=literal>getMultiplier</tt>();
            public String <tt CLASS=literal>getNegativePrefix</tt>();
            public String <tt CLASS=literal>getNegativeSuffix</tt>();
            public String <tt CLASS=literal>getPositivePrefix</tt>();
            public String <tt CLASS=literal>getPositiveSuffix</tt>();
            public int <tt CLASS=literal>hashCode</tt>();  //<tt CLASS=literal> Overrides NumberFormat</tt>
            public boolean <tt CLASS=literal>isDecimalSeparatorAlwaysShown</tt>();
            public Number <tt CLASS=literal>parse</tt>(String <tt CLASS=literal>text</tt>, ParsePosition <tt CLASS=literal>status</tt>);  //<tt CLASS=literal> Defines NumberFormat</tt>
            public void <tt CLASS=literal>setDecimalFormatSymbols</tt>(DecimalFormatSymbols <tt CLASS=literal>newSymbols</tt>);
            public void <tt CLASS=literal>setDecimalSeparatorAlwaysShown</tt>(boolean <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setGroupingSize</tt>(int <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setMultiplier</tt>(int <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setNegativePrefix</tt>(String <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setNegativeSuffix</tt>(String <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setPositivePrefix</tt>(String <tt CLASS=literal>newValue</tt>);
            public void <tt CLASS=literal>setPositiveSuffix</tt>(String <tt CLASS=literal>newValue</tt>);
            public String <tt CLASS=literal>toLocalizedPattern</tt>();
            public String <tt CLASS=literal>toPattern</tt>();
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-29-SECT-9.2">Hierarchy:</A></h3>

<P CLASS=para>
Object->Format(Serializable, Cloneable)->NumberFormat(Cloneable)->DecimalFormat

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch29_08.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch29_10.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.text.DateFormatSymbols (JDK 1.1)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.text.DecimalFormatSymbols (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
